<?php
namespace Trawind\Skeleton\Generators\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Prettus\Repository\Generators\FileAlreadyExistsException;
use Prettus\Repository\Generators\Generator;
use Prettus\Repository\Generators\MigrationGenerator;
use Trawind\Skeleton\Generators\ModelGenerator;
use Prettus\Repository\Generators\PresenterGenerator;
use Trawind\Skeleton\Generators\RemoteInterfaceGenerator;
use Trawind\Skeleton\Generators\RemoteRepositoryEloquentGenerator;
use Trawind\Skeleton\Generators\TransformerGenerator;
use Trawind\Skeleton\Generators\RepositoryEloquentGenerator;
use Trawind\Skeleton\Generators\RepositoryInterfaceGenerator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

/**
 * Class RepositoryCommand
 * @package Prettus\Repository\Generators\Commands
 * @author Anderson Andrade <contato@andersonandra.de>
 */
class RemoteCommand extends Command
{

    /**
     * The name of command.
     *
     * @var string
     */
    protected $name = 'make:skeleton-remote';

    /**
     * The description of command.
     *
     * @var string
     */
    protected $description = 'Create a new remote.';

    /**
     * The type of class being generated.
     *
     * @var string
     */
    protected $type = 'Repository';

    /**
     * @var Collection
     */
    protected $generators = null;


    /**
     * Execute the command.
     *
     * @see fire()
     * @return void
     */
    public function handle(){
        $this->laravel->call([$this, 'fire'], func_get_args());
    }

    /**
     * Execute the command.
     *
     * @return void
     */
    public function fire()
    {
        $this->generators = new Collection();

        if ($this->confirm('Would you like to create a Remote? [y|N]')) {
            $this->generators->push(new RemoteInterfaceGenerator([
                'name'     => $this->argument('name'),
                'force'    => $this->option('force')
            ]));

            $this->generators->push(new RemoteRepositoryEloquentGenerator([
                'name'     => $this->argument('name'),
                'force'    => $this->option('force')
            ]));
        }

        foreach ($this->generators as $generator) {
            $generator->run();
        }

        $this->info("Remote created successfully.");
    }


    /**
     * The array of command arguments.
     *
     * @return array
     */
    public function getArguments()
    {
        return [
            [
                'name',
                InputArgument::REQUIRED,
                'The name of class being generated.',
                null
            ],
        ];
    }


    /**
     * The array of command options.
     *
     * @return array
     */
    public function getOptions()
    {
        return [
            [
                'force',
                'f',
                InputOption::VALUE_NONE,
                'Force the creation if file already exists.',
                null
            ],
        ];
    }
}
